package br.com.musclebook.bean;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import javax.inject.Named;

import br.com.musclebook.entity.Routine;
import br.com.musclebook.service.RoutineService;

@Named
@ViewScoped
public class ListRoutineBean implements Serializable {

    private static final long serialVersionUID = 1L;

    @Inject
    private SessionInfoBean sessionInfoBean;

    @Inject
    private RoutineService routineService;

    private List<Routine> routines;
    
    public boolean isDefaultRoutineLoaded() {
	for(Routine routine : this.routines) {
	    if(routine.isUserCurrentRoutine()) {
		return true;
	    }
	}
	
	return false;
    }

    public void list(ComponentSystemEvent evt) {
	this.routines = this.routineService.list(this.sessionInfoBean.getUserId());
    }

    public SessionInfoBean getSessionInfoBean() {
	return sessionInfoBean;
    }

    public void setSessionInfoBean(SessionInfoBean sessionInfoBean) {
	this.sessionInfoBean = sessionInfoBean;
    }

    public List<Routine> getRoutines() {
	return routines;
    }

    public void setRoutines(List<Routine> routines) {
	this.routines = routines;
    }

}
